package org.byqh.dqeai.config.easyquery;

import com.easy.query.api.proxy.client.EasyEntityQuery;
import com.easy.query.core.api.client.EasyQueryClient;
import org.byqh.dqeai.config.datasource.DataSource;
import org.byqh.dqeai.config.datasource.DataSourceNames;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class EasyQueryClass implements InitializingBean {
    @Autowired
    private EasyQueryService service;

    protected EasyEntityQuery easyEntityQuery;
    protected EasyQueryClient easyQueryClient;

    @Override
    public void afterPropertiesSet() {
        DataSource annotation = this.getClass().getAnnotation(DataSource.class);
        String value = DataSourceNames.Default;

        if (annotation != null) {
            value = annotation.value();
        }

        easyEntityQuery = service.getEasyEntityQuery(value);
        easyQueryClient = service.getEasyQueryClient(value);
    }
}
